<template>
  <!--模态窗 多行-->
  <transition
    name="custom-classes-transition"
    enter-active-class="animated fadeInDown"
    leave-active-class="animated fadeOutUp"
  >
    <div class="modal-ctrl-body" v-show="RevampModalObj.isShow">
      <div class="modal-ctrl-main even-row-ctrl">

        <div class="modal-title">
          <p>修改点位信息</p>
        </div>

        <div class="modal-ctrl-content">
          <div class="even-row">

            <div class="modal-row" >
              <div class="modal-form-key f-l indispensable">
                地址：
              </div>
              <input type="text" maxlength="64" placeholder="最长64个字符" v-model="ModalData.address" class="modal-text f-l">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l indispensable">
                名称：
              </div>
              <input type="text" maxlength="64" placeholder="最长64个字符" v-model="ModalData.name" class="modal-text f-l">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l indispensable">
                所属单位：
              </div>
              <input type="text" v-model="stationName" @click="getStationTree" readonly="readonly" class="modal-text f-l" >
              <input type="hidden" v-model="ModalData.stationid">
              <div class="sectionTree" v-show="sectionTreeIShow">
                <div id="sectionRevampTree" class="ztree sectionTree-box"></div>
              </div>
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l indispensable">
                点位名称：
              </div>
              <input type="text" maxlength="32" placeholder="最长32个字符" v-model="ModalData.pointName" class="modal-text f-l">
            </div>


            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                点对象编码：
              </div>
              <input type="text" maxlength="32" placeholder="最长32个字符" v-model="ModalData.pointcode" class="modal-text f-l">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                经度：
              </div>
              <input type="text" v-model="ModalData.longitude" class="modal-text f-l">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                纬度：
              </div>
              <input type="text" v-model="ModalData.latitude" class="modal-text f-l">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                属性扩展表：
              </div>
              <input type="text" readonly="readonly" v-model="ModalData.owner" class="modal-text f-l">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                资源类型编码：
              </div>
              <input type="text" readonly="readonly" v-model="ModalData.resourceTypeCode" class="modal-text f-l">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                备注：
              </div>
              <input type="text" maxlength="500" placeholder="最长500个字符" v-model="ModalData.remark" class="modal-text f-l">
            </div>

          </div>

        </div>
        <div class="btns text-r">
          <button type="button" class="btn btn-default"  @click="close">取消</button>
          <button type="button" class="btn btn-info" @click="subBtn">确定</button>
        </div>
        <!--{{userDetailsModal.obj}}-->
      </div>
    </div>
  </transition>
</template>

<script>
    export default {
        name: "AddOldDotModal",
        props:["RevampModalObj","selectRowId"],
        data(){
          return{
            ModalData:{
              address:'', //地址
              name:'', //名称
              pointcode:'', //点对象编码
              pointName:'', //点位名称
              latitude:"",//经度
              longitude:"",//纬度
              owner:'T_RES_GENERIC_POINT',//扩展属性表
              resourceTypeCode:'应急围堵点',//资源类型编码
              remark:'',//备注
              stationid:""
            },
            carTypeList:[],
            stationName:'',
            setting : {
              data: {
                simpleData: {
                  enable: true
                },
              }
            },
            sectionTreeIShow:false,
            selectId:""
          }
        },
        mounted(){
          let _this = this;
          this.setting.callback = {
            onClick:function(event,treeId,treeNode){ //新增警员部门树选择
              //console.log(treeNode);
              _this.ModalData.stationid = treeNode.id;
              _this.stationName = treeNode.name;
              _this.sectionTreeIShow = !_this.sectionTreeIShow;
            }
          };
        },
        watch:{
          RevampModalObj:{
            handler(v1){
              if( v1.isShow ){
                this.selectId = this.selectRowId;
                this.getDotData();
              }
            },
            deep:true
          }
        },
        methods:{
          //资源详细信息
          getDotData(){
            this.$axios.get(this.DotCtrl+"/resource/genericPoint/id/"+this.selectId)
              .then(data=>{
                //console.log(data);

                let successData = data.data;
                for( let successKey in successData ){
                  for( let ModalDataKey in this.ModalData ){

                    if( successKey === ModalDataKey ){
                      this.ModalData[ModalDataKey] = successData[successKey];
                    }else if( successKey === "stationName" ){
                      this.stationName = successData[successKey];
                    }
                  }
                }

                //console.log(this.ModalData);
              })
              .catch(err=>{
                //console.log(err);
              })
          },
          //提交
          subBtn(){
             //console.log(this.ModalData);
            //return false;
            if( this.verifyForm.isNull(this.ModalData.address) ){
              this.s_alert("地址不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.ModalData.name) ){
              this.s_alert("名称不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.ModalData.pointName) ){
              this.s_alert("点位名称不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.ModalData.stationid) ){
              this.s_alert("所属单位不能为空！");
              return false;
            }
            else if( this.verifyForm.ifLongitude(this.ModalData.longitude) ){
              this.s_alert("经度格式不正确！");
              return false;
            }
            else if( this.verifyForm.ifLatitude(this.ModalData.latitude) ){
              this.s_alert("纬度格式不正确！");
              return false;
            }
            this.$axios.put(this.DotCtrl+"/resource/genericPointCRUD/updateGenericPoint/"+this.selectId,this.ModalData)
              .then((data)=>{
                //console.log(data);
                this.s_alert("修改成功！");
                this.close();
              })
              .catch((err)=>{
                this.s_alert("修改失败！");
                //console.log(err);
              })
          },
          //是否在线
          selectIsOnline(ele){
            ////console.log(ele.target.value);
            this.ModalData.isonline = ele.target.value;
          },
          selectCameraType(ele){
            ////console.log(ele.target.value);
            this.ModalData.category = ele.target.value;
          },
          attrTable(ele){
            ////console.log(ele.target.value);
            this.ModalData.code = ele.target.value
          },
          //展开部门树
          getStationTree(){
            this.sectionTreeIShow = !this.sectionTreeIShow;
            if( this.sectionTreeIShow ){
              this.getStationTreeAjax()
            }
          },
          //加载部门树
          getStationTreeAjax(){
            this.$axios.get(this.HOST+'/station/getOrgaInfo')
              .then((data)=>{
                $.fn.zTree.init($("#sectionRevampTree"), this.setting, data.data.data);
                //console.log(data);
              })
              .catch((err)=>{
                //console.log(err);
              })
          },
          //关闭弹窗
          close(){
            this.$emit("closeRevampModal");
            this.clearData(); //关闭弹窗清除数据
          },
          //清除数据
          clearData(){
            this.ModalData={
              address:'', //地址
              name:'', //名称
              pointcode:'', //点对象编码
              pointName:'', //点位名称
              latitude:"",//经度
              longitude:"",//纬度
              owner:'T_RES_GENERIC_POINT',//扩展属性表
              resourceTypeCode:'应急围堵点',//资源类型编码
              remark:'',//备注
              stationid:""
            };
            this.stationName='';
          }
        },
    }
</script>

<style scoped>
  .sectionTree{
    position: absolute;
    top: 30px;
    right: 0;
    width: 60%;
    z-index: 2;
    background-color: #fff;
    border:1px solid rgba(51,51,51,0.2);
    box-sizing: border-box;
    padding: 5px;
    max-height: 200px;
    overflow-y: auto;
  }
  .fadeInDown,.fadeOutUp{
    animation-duration: .500s;
  }
  .form-control {
    height: 100%;
    border: 1px solid #ccc;
  }
</style>
